package com.yh.modules.data.controller;

import java.util.Arrays;
import java.util.Map;

import com.yh.common.utils.PageUtils;
import com.yh.common.utils.R;
import com.yh.common.utils.ValidatorUtils;
import com.yh.modules.data.entity.ErrorTypeEntity;
import com.yh.modules.data.service.ErrorTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 错误类型
 */
@RestController
@RequestMapping("/errorType")
public class ErrorTypeController {

	@Autowired
	private ErrorTypeService errorTypeService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("data:errorType:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = errorTypeService.queryPage(params);

		return R.ok().put("page", page);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("data:errorType:info")
	public R info(@PathVariable("id") Integer id) {
		ErrorTypeEntity errorType = errorTypeService.selectById(id);

		return R.ok().put("errorType", errorType);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("data:errorType:save")
	public R save(@RequestBody ErrorTypeEntity errorType) {
		ValidatorUtils.validateEntity(errorType);

		errorTypeService.insert(errorType);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("data:errorType:update")
	public R update(@RequestBody ErrorTypeEntity errorType) {
		ValidatorUtils.validateEntity(errorType);
		errorTypeService.updateById(errorType);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("data:errorType:delete")
	public R delete(@RequestBody Integer[] ids) {
		errorTypeService.deleteBatchIds(Arrays.asList(ids));

		return R.ok();
	}

}
